/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-03-22 16:18:10
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-03-25 17:01:34
 */
import dom from "./dom";

export default {
  hasClass: (node, className) => {
    if (node.classList) {
      return node.classList.contains(className);
    }
    const originClass = node.className;
    return (" " + originClass + " ").indexOf(" " + className + " ") > -1;
  },
  addClass: (node, className) => {
    if (node.classList) {
      node.classList.add(className);
    } else {
      if (!dom.hasClass(node, className)) {
        node.className = node.className + " " + className;
      }
    }
  },

  removeClass: function (node, className) {
    if (node.classList) {
      node.classList.remove(className);
    } else {
      if (this.hasClass(node, className)) {
        const originClass = node.className;
        node.className = (" " + originClass + " ").replace(
          " " + className + " ",
          ""
        );
      }
    }
  }
};
